///////////////////////////////////////////////////////////
// 
//  MyStage.h
//
//  Wiicussion
//  HCI 575 Class project
//  Spring 2007
// 
//  Authors:  Jeremy Bennett
//            Adam Faeth
//            Michael Oren
//
//  This class developed for Adam's 557 project
//
//
///////////////////////////////////////////////////////////

// Local Includes
#include "stdafx.h"
#include "Instrument.h"
#include "MyContext.h"

// SDL Includes
#include <SDL_opengl.h>

// System Includes
#include <iostream>

// Scaling factors to get the sizes of the instruments down    
const float _fInstSize[NUM_INSTS][3] = {
    {  65.0f,  65.0f,  90.0f },  // INST_BASE_HIGHMIDTOM
    { 100.0f, 100.0f, 150.0f },  // INST_BASE_BASSDRUM
    {  50.0f,  50.0f,  50.0f },  // INST_BASE_HIHAT
    {  80.0f,  80.0f, 110.0f },  // INST_BASE_LOWTOM
    {  60.0f,  60.0f,  90.0f },  // INST_BASE_SNARE
    {  90.0f,  90.0f,  70.0f }   // INST_BASE_CRASHCYMBAL
};

const float _fInstRot[NUM_INSTS][4] = {
    { -60.0f, 1.0f, 0.0f, 0.0f },  // INST_BASE_HIGHMIDTOM
    { -60.0f, 1.0f, 0.0f, 0.0f },  // INST_BASE_BASSDRUM
    { -60.0f, 1.0f, 0.0f, 0.0f },  // INST_BASE_HIHAT
    { -60.0f, 1.0f, 0.0f, 0.0f },  // INST_BASE_LOWTOM
    { -60.0f, 1.0f, 0.0f, 0.0f },  // INST_BASE_SNARE
    { -60.0f, 1.0f, 0.0f, 0.0f }   // INST_BASE_CRASHCYMBAL
};


// Constructor
Instrument::Instrument()
: _uiType(0)
{
    // position
    _fRenderPos[0] = 0.0f;
    _fRenderPos[1] = 0.0f;
    _fRenderPos[2] = 0.0f;
    
    _fRenderSize[0] = 1.0f;
    _fRenderSize[1] = 1.0f;
    _fRenderSize[2] = 1.0f;
    
    _fRotate[0] = 0.0f;
    _fRotate[1] = 1.0f;
    _fRotate[2] = 0.0f;
    _fRotate[3] = 0.0f;
}


// destructor
Instrument::~Instrument()
{
    // nothing to do
}


// Set method w/o size
bool
Instrument::set(unsigned int uiType, float fX, float fY, float fZ)
{
    _uiType = uiType;
    // position
    _fRenderPos[0] = fX;
    _fRenderPos[1] = fY;
    _fRenderPos[2] = fZ;
    
    _fRenderSize[0] = _fInstSize[uiType][0];
    _fRenderSize[1] = _fInstSize[uiType][1];
    _fRenderSize[2] = _fInstSize[uiType][2];
    
    _fRotate[0] = _fInstRot[uiType][0];
    _fRotate[1] = _fInstRot[uiType][1];
    _fRotate[2] = _fInstRot[uiType][2];
    _fRotate[3] = _fInstRot[uiType][3];
    return true;
}



// Set method w/ size
bool
Instrument::set(unsigned int uiType, float fX, float fY, float fZ, float fW, float fH, float fD)
{
    Instrument::set(uiType, fX, fY, fZ);
    
    _fRenderSize[0] = fW * _fInstSize[uiType][0];
    _fRenderSize[1] = fH * _fInstSize[uiType][1];
    _fRenderSize[2] = fD * _fInstSize[uiType][2];
    return true;
}


// Renders the instrument based on MIDI type
bool 
Instrument::renderInstrument(MyContext * pContext)
{

//    std::cout << "Inst: " << _uiType << ", Position: (" << _fRenderPos[0] << "," << _fRenderPos[1] << "," << _fRenderPos[2] << ") Size: " << _fRenderSize[0] << "x" << _fRenderSize[1] << "x" << _fRenderSize[2] << std::endl;
    switch(_uiType) 
    {
        case INST_BASE_BASSDRUM:
        case INST_BASE_SNARE:
        case INST_BASE_LOWTOM: 
        case INST_BASE_HIGHMIDTOM:   
            pContext->renderCylinder(_fRenderSize, _fRenderPos, _fRotate, _uiType);
        break;
        case INST_BASE_CRASHCYMBAL: 
        case INST_BASE_HIHAT:        
            pContext->renderCone(_fRenderSize, _fRenderPos, _fRotate, _uiType);
        break;
    }
    return true;
}


